package com.wk.code.wkserver.controller.app;

import com.wk.code.wkserver.controller.common.BaseController;
import com.wk.code.wkserver.request.app.DemandPageRequest;
import com.wk.code.wkserver.request.app.DemandRequest;
import com.wk.code.wkserver.request.base.BasePageRequest;
import com.wk.code.wkserver.response.admin.DemandResponse;
import com.wk.code.wkserver.response.app.AppDemandResponse;
import com.wk.code.wkserver.response.result.R;
import com.wk.code.wkserver.service.IDemandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-08-15
 */
@RestController
@RequestMapping("/demand")
@AllArgsConstructor
@Api(tags = "app-前台需求管理")
public class DemandController extends BaseController {

    final IDemandService demandService;


    /**
     * 发布
     *
     * @param request 请求参数
     * @return R
     */
    @ApiOperation(value = "发布需求", notes = "发布需求")
    @PostMapping("/publish")
    public R<Void> publish(@RequestBody DemandRequest request) {
        demandService.publish(getUserId(), request);
        return R.success();
    }

    /**
     * 分页列表
     *
     * @param request 请求参数
     * @return R
     */
    @ApiOperation(value = "分页列表")
    @PostMapping("/page")
    public R<List<AppDemandResponse>> acquire(@RequestBody DemandPageRequest request) {
        return R.success(demandService.acquire(request));
    }


    /**
     * 我的需求列表
     *
     * @return R
     */
    @ApiOperation(value = "我的需求列表")
    @GetMapping("/mineDemand")
    public R<List<AppDemandResponse>> mineDemandList() {
        return R.success(demandService.mineDemand(getUserId()));
    }


    /**
     * 详情
     *
     * @param id ID
     * @return R
     */
    @ApiOperation(value = "详情")
    @GetMapping("/detail")
    public R<AppDemandResponse> detail(Integer id) {
        return R.success(demandService.demandDetail(getUserId(), id));
    }

    /**
     * 更新浏览量
     *
     * @param id 需求ID
     * @return R
     */
    @ApiOperation(value = "更新浏览量")
    @GetMapping("/updateViewCount")
    public R<Void> updateViewCount(Integer id) {
        demandService.updateViewCount(id);
        return R.success();
    }


    /**
     * 技术申请接单
     *
     * @param demandId 需求ID
     * @return R
     */
    @ApiOperation(value = "申请接单")
    @GetMapping("/applyOrderTaking")
    public R<Void> applyOrderTaking(Integer demandId) {
        demandService.applyOrderTaker(demandId, getUserId());
        return R.success();
    }

    /**
     * 删除需求
     *
     * @param demandId 需求ID
     * @return R<Void>
     */
    @ApiOperation(value = "删除需求")
    @GetMapping("/deleteDemand")
    public R<Void> deleteDemand(Integer demandId) {
        demandService.deleteDemand(demandId, getUserId());
        return R.success();
    }

}
